<?php
/*
    OpenLib
    Copyright (C) 2011  Michael Gukov, Pham Thi Thuy Duong

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


namespace App\Views\Lib;

use Sun\Html;
use Sun\Html\Form;
use App\Models;
use App\Models\DB;

class Catalog extends Main {
    public function __construct() {
        parent::__construct();
        $this->data_scene = 'Main';
    }


    public function FieldList($id, $sel = false) {

        $select = new Html\Form\Select(array(
            'class' => 'MiddleWide',
            'id' => $id,
            'multiple' => 'multiple',
            'size' => '15'
        ));

        if ($sel) $fields = $this->data['cat_fields'];
        else $fields = $this->data['fields'];

        foreach ($fields as $field) {
            $select->AddOption($field['field_id'], $field['name']);
        }
        return $select;
    }

    public function MainScene() {

        $edit = new Models\Edition();
        $this->data['cat_fields'] = $edit->GetCatalogFields();
        $this->data['fields'] = $edit->GetNoneCatalogFields();

        $this->IncludeScene("FieldList");
    }
}
